

if ( SERVER ) then

	AddCSLuaFile( "shared.lua" )
	
end

if ( CLIENT ) then

	SWEP.PrintName			= "M249"			
	SWEP.Author				= "Counter-Strike"
	SWEP.Slot				= 2
	SWEP.SlotPos			= 0
	SWEP.IconLetter			= "z"
	SWEP.ViewModelFlip		= false
	
	killicon.AddFont( "weapon_m249", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )
	
end

SWEP.HoldType			= "ar2"
SWEP.Base				= "weapon_cs_base2_ds"

SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true

SWEP.ViewModel			= "models/weapons/v_mach_m249para.mdl"
SWEP.WorldModel			= "models/weapons/w_mach_m249para.mdl"

SWEP.Weight				= 5
SWEP.AutoSwitchTo		= false
SWEP.AutoSwitchFrom		= false

SWEP.Primary.Sound			= Sound( "Weapon_m249.Single" )
SWEP.Primary.Recoil			= 1.6
SWEP.Primary.Damage			= 20
SWEP.Primary.NumShots		= 1
SWEP.Primary.Cone			= 0.015
SWEP.Primary.ClipSize		= 100
SWEP.Primary.Delay			= 0.09
SWEP.Primary.DefaultClip	= 300
SWEP.Primary.Automatic		= true
SWEP.Primary.Ammo			= "smg1"

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false
SWEP.Secondary.Ammo			= "none"



function SWEP:CSShootBullet( dmg, recoil, numbul, cone )

	numbul = numbul or 1
	cone = cone or 0.01
	cone = ( self.Owner:GetVelocity():Length() > 150 ) and cone + ( self.Owner:GetVelocity():Length() / 10000 ) or cone

	local bullet = {}
	bullet.Num 		= numbul
	bullet.Src 		= self.Owner:GetShootPos()			// Source
	bullet.Dir 		= self.Owner:GetAimVector()			// Dir of bullet
	bullet.Spread 	= Vector( cone, cone, 0 )			// Aim Cone
	bullet.Tracer	= 2									// Show a tracer on every x bullets 
	bullet.Force	= 5									// Amount of force to give to phys objects
	bullet.Damage	= dmg
	local SWEPOWNER = self.Owner
	bullet.Callback	= function( attacker, tr, dmginfo )
			local dist = ( tr.HitPos - tr.StartPos ):Length()
			if dist > 500 then return end
			local traceres = {}

			local shdist = 50
			shdist = ( tr.MatType == 67 ) and 20 or shdist
			shdist = ( tr.MatType == 77 ) and 10 or shdist

			traceres.start = tr.HitPos + tr.Normal * shdist
			traceres.endpos = tr.HitPos
			local trace = util.TraceLine( traceres )
			if trace.Hit then
				local bullet = {}
				bullet.Num 		= numbul
				bullet.Src 		= trace.HitPos - trace.Normal			// Source
				bullet.Dir 		= tr.Normal	// Dir of bullet
				bullet.Spread 	= Vector( 0, 0, 0 )			// Aim Cone
				bullet.Tracer	= 2									// Show a tracer on every x bullets 
				bullet.Force	= 5									// Amount of force to give to phys objects
				bullet.Damage	= dmg
				SWEPOWNER:LagCompensation( false )
				SWEPOWNER:FireBullets( bullet )
				SWEPOWNER:LagCompensation( true )
			end
		end
	self.Owner:FireBullets( bullet )
	self:TakePrimaryAmmo( 1 )
	self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
	self.Owner:MuzzleFlash()
	self.Weapon:EmitSound( self.Primary.Sound )
	self.Owner:SetAnimation( PLAYER_ATTACK1 )								// Crappy muzzle light				// 3rd Person Animation
	if self.Owner:IsNPC() then return end
	
	if ( (SinglePlayer() && SERVER) || ( !SinglePlayer() && CLIENT && IsFirstTimePredicted() ) ) then
	
		local eyeang = self.Owner:EyeAngles()
		eyeang.pitch = eyeang.pitch - recoil
		self.Owner:SetEyeAngles( eyeang )
	end
end